home *** CD-ROM | disk | FTP | other *** search
- /*
- File: GXEditUtils.c
-
- Contains:
-
- Written by: Barton R. House
-
- Copyright: © 1993 by Apple Computer, Inc., All rights reserved.
-
- */
-
- #include "GXEdit.h"
- #include "GXEditDoc.h"
- #include "GXEditDebug.h"
- #define _GXEditUtilsPrivate_
- #include "GXEditUtils.h"
-
- #include "graphics routines.h"
- #include "math routines.h"
-
- Boolean gxEditSetBitMaskOp(char * src, char * dst, char * mask, long size)
- {
- Boolean modified;
- char val;
-
- modified = false;
-
- while(size--) {
-
- val = (*dst & ~(*mask)) | (*src & *mask);
-
- if(val != *dst) {
-
- modified = true;
- *dst = val;
-
- }
-
- src++;
- dst++;
- mask++;
-
- }
-
- return(modified);
-
- }
-
- void gxEditGetBitMaskOp(char * src, char * dst, char * mask, long size, Boolean firstTime)
- {
- if(firstTime) {
-
- while(size--) {
- *dst++ = *src++;
- *mask++ = 0xff;
- }
-
- } else {
-
- while(size--) {
-
- if(*src != *dst)
- *mask &= ~(*src ^ *dst);
- src++;
- dst++;
- mask++;
-
- }
- }
- }
-
- void gxEditDisposeOffscreen(DocPtr dp)
- {
-
- if(dp->offscreenBytes != nil)
- DisposePtr(dp->offscreenBytes);
-
- if(dp->offscreenBitmap != nil)
- GXDisposeShape(dp->offscreenBitmap);
-
- if(dp->offscreenPort != nil)
- GXDisposeViewPort(dp->offscreenPort);
-
- if(dp->offscreenDevice != nil)
- GXDisposeViewDevice(dp->offscreenDevice);
-
- if(dp->offscreenGroup != nil)
- GXDisposeViewGroup(dp->offscreenGroup);
-
- }
-
-
- void gxEditBuildOffscreen(DocPtr dp)
- {
- gxBitmap bitmapRec;
- long height;
- long width;
- long rowBytes;
- gxPoint bitmapPos;
- gxMapping deviceMatrix;
-
- height = dp->viewRect.bottom - dp->viewRect.top;
- width = dp->viewRect.right - dp->viewRect.left;
- rowBytes = (width + 7) / 8;
- rowBytes = (rowBytes + 0x3L) & ~0x3L;
-
- if(dp->offscreenBytes != nil)
- DisposePtr(dp->offscreenBytes);
-
- dp->offscreenBytes = NewPtr(rowBytes * height);
-
- bitmapRec.image = dp->offscreenBytes;
- bitmapRec.width = width;
- bitmapRec.height = height;
- bitmapRec.rowBytes = rowBytes;
- bitmapRec.pixelSize = 1;
- bitmapRec.space = gxIndexedSpace;
- bitmapRec.set = nil;
- bitmapRec.profile = nil;
-
- bitmapPos.x = ff(dp->viewRect.left);
- bitmapPos.y = ff(dp->viewRect.top);
-
- if(dp->offscreenBitmap == nil)
- dp->offscreenBitmap = GXNewBitmap(&bitmapRec, &bitmapPos);
- else
- GXSetBitmap(dp->offscreenBitmap, &bitmapRec, &bitmapPos);
-
- if(dp->offscreenGroup == nil)
- dp->offscreenGroup = GXNewViewGroup();
-
- if(dp->offscreenDevice == nil)
- dp->offscreenDevice = GXNewViewDevice(dp->offscreenGroup, dp->offscreenBitmap);
- else
- GXSetViewDeviceBitmap(dp->offscreenDevice, dp->offscreenBitmap);
-
- if(dp->offscreenPort == nil)
- dp->offscreenPort = GXNewViewPort(dp->offscreenGroup);
-
- ResetMapping(&deviceMatrix);
- MoveMappingTo(&deviceMatrix, ff(-dp->viewRect.left), ff(-dp->viewRect.top));
- GXSetViewDeviceMapping(dp->offscreenDevice, &deviceMatrix);
-
- }
-
- void gxEditFlushCaches(DocPtr dp)
- {
- ParaRec* para = *dp->paragraphs;
- short paraCount = dp->numParagraphs;
-
- while (paraCount--)
- { LineRec* gxLine = *para->lines;
- short lineCount = para->numLines;
-
- while (lineCount--)
- { gxLine->dirty = true;
- ++gxLine;
- }
- ++para;
- }
- }
-
-
-